/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.dict.service.plugins  
 */
package com.apache.dict.service.plugins;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.apache.api.api.PlatformService;
import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.dict.entity.DataItem;
import com.apache.dict.vo.ItemListVo;

/**
 * description:  外部系统select控件加载数据字典数据
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class WsDictSelectPlugin implements PluginConnector {
	private Logger logger = LoggerFactory.getLogger(getClass());
	private PlatformService<DataItem> dictInnerService;

	/**
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	@Override
	public Object execute(ParamsVo arg0) throws Exception {
		ResultEntity result = new ResultEntity();
		result.setEntity(null);
		result.setMessage("查询失败！");
		result.setResult("false");

		String cateEname = (String) arg0.getParams("cateEname");
		String fatherValue = (String) arg0.getParams("fatherValue");
		this.logger.info("cateEname=" + cateEname + ", fatherValue=" + fatherValue);
		if (Validator.isNull(cateEname) || Validator.isNull(fatherValue)) {
			result.setMessage("缺少必要的参数：cateEname或者fatherValue为空！");
			return result;
		}

		ParamsVo vo = new ParamsVo();
		ItemListVo item = new ItemListVo();
		item.setCateEname(cateEname);
		item.setFatherValue(fatherValue);
		String methodKey = "getList";
		vo.setMethodKey(methodKey);
		vo.setObj(item);

		String jsonStr = dictInnerService.doService(vo);
		if (Validator.isNotNull(jsonStr)) {
			result.setEntity(jsonStr);
			result.setMessage("查询成功！");
			result.setResult("true");
		}

		return result;
	}

	public void setDictInnerService(PlatformService<DataItem> dictInnerService) {
		this.dictInnerService = dictInnerService;
	}

}
